package com.zhitan.ems.app.sse;

import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.zhitan.ems.common.constant.HttpStatus;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

/***
 * 返回客户端通知对象
 * @author zhitan
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ClientNotifyVo implements Serializable {
    private static final long serialVersionUID = 1L;
    
	/** 返回状态码 code200=成功 500=异常*/
    private int code;
    private String msg;
    private Object data;
    /**操作类型*/
    private ClientOptType optType;
    
    public ClientNotifyVo(ClientOptType optType, Object data) {
        this.data = data;
        this.optType = optType;
        this.code = HttpStatus.SUCCESS;
    }
    
    public ClientNotifyVo success(Object data) {
        this.data = data;
        this.code = HttpStatus.SUCCESS;
        this.msg = "success";
        return this;
    }
    
    public ClientNotifyVo error(String msg) {
        this.msg = msg;
        this.code = HttpStatus.ERROR;
        return this;
    }
    
    public ClientNotifyVo error(int code, String msg) {
        this.msg = msg;
        this.code = code;
        return this;
    }
}